<?php
require_once 'config.php';
require_once 'common.php';
require_once 'ResultData.php';

$result = new ResultData();

$course_name = trim($_REQUEST['courseName']);
$course_no = trim($_REQUEST['courseNo']);


if ($course_name == "") {
    $result->code = 404;
    $result->msg = "courseName未填写";
    exit(json_encode($result));
}

if ($course_no == "") {
    $result->code = 404;
    $result->msg = "courseNo未填写";
    exit(json_encode($result));
}

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}

$sql = "INSERT INTO t_course(course_name, course_no) VALUES('{$course_name}','{$course_no}');";

$con->query($sql);

mysqli_close($con);

exit(json_encode($result));
